package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AppVersionUpdate;
import com.ruoyi.system.service.IAppVersionUpdateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * APP管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-08
 */
@RestController
@RequestMapping("/system/update")
public class AppVersionUpdateController extends BaseController
{
    @Autowired
    private IAppVersionUpdateService appVersionUpdateService;


    @ApiOperation("获取版本更新信息")
    @GetMapping("/getVersionUpdateInfo")
    public AjaxResult getVersionUpdateInfo(@RequestParam String type)
    {
        return AjaxResult.success(appVersionUpdateService.getVersionUpdateInfo(type));
    }


    /**
     * 查询APP管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:update:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppVersionUpdate appVersionUpdate)
    {
        startPage();
        List<AppVersionUpdate> list = appVersionUpdateService.selectAppVersionUpdateList(appVersionUpdate);
        return getDataTable(list);
    }


    /**
     * 导出APP管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:update:export')")
    @Log(title = "APP管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppVersionUpdate appVersionUpdate)
    {
        List<AppVersionUpdate> list = appVersionUpdateService.selectAppVersionUpdateList(appVersionUpdate);
        ExcelUtil<AppVersionUpdate> util = new ExcelUtil<AppVersionUpdate>(AppVersionUpdate.class);
        return util.exportExcel(list, "APP管理数据");
    }

    /**
     * 获取APP管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:update:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(appVersionUpdateService.selectAppVersionUpdateById(id));
    }

    /**
     * 新增APP管理
     */
    @PreAuthorize("@ss.hasPermi('system:update:add')")
    @Log(title = "APP管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppVersionUpdate appVersionUpdate)
    {

        appVersionUpdate.setInsertBy(SecurityUtils.getLoginUser().getUser().getUserName());
        return toAjax(appVersionUpdateService.insertAppVersionUpdate(appVersionUpdate));
    }

    /**
     * 修改APP管理
     */
    @PreAuthorize("@ss.hasPermi('system:update:edit')")
    @Log(title = "APP管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppVersionUpdate appVersionUpdate)
    {
        return toAjax(appVersionUpdateService.updateAppVersionUpdate(appVersionUpdate));
    }

    /**
     * 删除APP管理
     */
    @PreAuthorize("@ss.hasPermi('system:update:remove')")
    @Log(title = "APP管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appVersionUpdateService.deleteAppVersionUpdateByIds(ids));
    }
}
